class ListViewClassic implements ListView {
	private var collection:Collection;
	private var hoverFormat:ListViewItem;
	private var normalFormat:ListViewItem;
	private var pressFormat:ListViewItem;
	private var _size:Point;
	private var mask:MovieClip;
	private var back:MovieClip;
	private var mcBorde:MovieClip;

	private var ALPHA_DEBUG_MASK=20;
	private var COLOR_BG:Number=0xf6f6FF;
	private var ALPHA_BG:Number=100;
	private var BORDER_SIZE:Number=1.5;
	private var BORDER_COLOR:Number=0xb9b9EE;
	private var BORDER_ALPHA:Number=100;
	private var HEIGHT_TEXT:Number;
	private var WIDTH_TEXT:Number=150;
	private var HTML:Boolean=true;
	
	private var HOVER_FONT:String="Tahoma";
		private var HOVER_SIZE:Number=11;
		private var HOVER_COLOR:Number=0x5555AA;
		private var HOVER_BOLD:Boolean=false;
		private var HOVER_ITALIC:Boolean=false;
		private var HOVER_ALIGN:String="left";
		private var HOVER_BG:Boolean=true;
		private var HOVER_BG_COLOR:Number=0x0000FF;
		private var HOVER_BG_ALPHA:Number=7;
		private var HOVER_LEFT_INDENT:Number=4;
	private var NORMAL_FONT:String="Tahoma";
		private var NORMAL_SIZE:Number=11;
		private var NORMAL_COLOR:Number=0x3e3e3e;
		private var NORMAL_BOLD:Boolean=false;
		private var NORMAL_ITALIC:Boolean=false;
		private var NORMAL_ALIGN:String="left";
		private var NORMAL_BG:Boolean=true;
		private var NORMAL_BG_COLOR:Number=0;
		private var NORMAL_BG_ALPHA:Number=0;
		private var NORMAL_LEFT_INDENT:Number=4;
	private var PRESS_FONT:String="Tahoma";
		private var PRESS_SIZE:Number=11;
		private var PRESS_COLOR:Number=0x5555AA;
		private var PRESS_BOLD:Boolean=true;
		private var PRESS_ITALIC:Boolean=false;
		private var PRESS_ALIGN:String="left";
		private var PRESS_BG:Boolean=true;
		private var PRESS_BG_COLOR:Number=0x0000FF;
		private var PRESS_BG_ALPHA:Number=20;
		private var PRESS_LEFT_INDENT:Number=4;
	
	function ListViewClassic() {
		reset();
		
		var tfHoverFormat:TextFormat=new TextFormat(HOVER_FONT, HOVER_SIZE, HOVER_COLOR, HOVER_BOLD, HOVER_ITALIC,null,null,null, HOVER_ALIGN, HOVER_LEFT_INDENT);
		var tfNormalFormat:TextFormat=new TextFormat(NORMAL_FONT, NORMAL_SIZE, NORMAL_COLOR, NORMAL_BOLD, NORMAL_ITALIC,null,null,null, NORMAL_ALIGN, NORMAL_LEFT_INDENT);
		var tfPressFormat:TextFormat=new TextFormat(PRESS_FONT, PRESS_SIZE, PRESS_COLOR, PRESS_BOLD, PRESS_ITALIC,null,null,null, PRESS_ALIGN, PRESS_LEFT_INDENT);
		hoverFormat=new ListViewItem();
		hoverFormat.setFormat(tfHoverFormat);
		hoverFormat.setBackgroundColor(HOVER_BG_COLOR);
		hoverFormat.setBackgroundAlpha(HOVER_BG_ALPHA);
		normalFormat=new ListViewItem();
		normalFormat.setFormat(tfNormalFormat);
		normalFormat.setBackgroundColor(NORMAL_BG_COLOR);
		normalFormat.setBackgroundAlpha(NORMAL_BG_ALPHA);
		pressFormat=new ListViewItem();
		pressFormat.setFormat(tfPressFormat);
		pressFormat.setBackgroundColor(PRESS_BG_COLOR);
		pressFormat.setBackgroundAlpha(PRESS_BG_ALPHA);

	}
	
	function getHoverFormat():ListViewItem{
		return hoverFormat;
	}
	function getNormalFormat():ListViewItem{
		return normalFormat;
	}
	function getPressFormat():ListViewItem{
		return pressFormat;
	}
	function setHoverFormat(format:ListViewItem):Void{
		hoverFormat=format;
	}
	function setNormalFormat(format:ListViewItem):Void{
		normalFormat=format;
	}
	function setPressFormat(format:ListViewItem):Void{
		pressFormat=format;
	}
	
	function getBorderSize():Number{
	return BORDER_SIZE;
	}
	function setBorderSize(borderSize:Number):Void{
	BORDER_SIZE=borderSize;
	}

	function getBorderColor():Number{
	return BORDER_COLOR;
	}
	function setBorderColor(borderColor:Number):Void{
	BORDER_COLOR=borderColor;
	}

	function getBorderAlpha():Number{
	return BORDER_ALPHA;
	}
	function setBorderAlpha(borderAlpha:Number):Void{
	BORDER_ALPHA=borderAlpha;
	}


	function getMask():MovieClip{
	return mask;
	}
	
	function getBack():MovieClip{
	return back;
	}

	function getScrollView():ScrollView{
	return new ScrollViewClassic;
	}

	function getItemSize():Point{
	calculateSize();
	return _size;
	}
	
	private function calculateSize():Void{
	var test:String="Aljibe y loco";
	var metrics1= hoverFormat.getFormat().getTextExtent(test);
	var metrics2= normalFormat.getFormat().getTextExtent(test);
	var metrics3= pressFormat.getFormat().getTextExtent(test);
	HEIGHT_TEXT=Math.max(metrics1.textFieldHeight, Math.max(metrics2.textFieldHeight, metrics3.textFieldHeight));
	_size=new Point(WIDTH_TEXT, HEIGHT_TEXT);
	}

	private function centerTextObject(textObject:TextField):Void{
	textObject._y=(HEIGHT_TEXT-4-textObject.textHeight)/2;
	}
	
	function newItem(item:CollectionItem,container:MovieClip):MovieClip {
		//Dibujo el movieclip
		WIDTH_TEXT=container._parent._width+BORDER_SIZE*2;
		var rect:Rectangulo=new Rectangulo(container,0,0,WIDTH_TEXT, HEIGHT_TEXT,0,30);
		var mcItem:MovieClip=rect.getClip();
		mcItem.rectangulo=rect;
		mcItem.createTextField("textObject", mcItem.getNextHighestDepth(), 0,0, WIDTH_TEXT, HEIGHT_TEXT);
		mcItem.textObject.selectable=false;
		mcItem.textObject.html=HTML;
		mcItem.textObject.htmlText=item.getValue();
		//Lo meto en mi coleccion con el mismo key del item
		//para poder modificarlo a piachere.
		collection.addItem(item.getKey(), mcItem.textObject);
		normalItem(item, container);
		return mcItem;	
	}
	
	function selectItem(item:CollectionItem,container:MovieClip):MovieClip {
		//Hace el efecto de cuando seleccionan un item.
		var textObject:TextField=TextField(collection.getItem(item.getKey()).getValue());
		textObject.setTextFormat(getPressFormat().getFormat());
		centerTextObject(textObject);
		textObject._parent.rectangulo.setColor(getPressFormat().getBackgroundColor());
		textObject._parent.rectangulo.setAlpha(getPressFormat().getBackgroundAlpha());
		textObject._parent.rectangulo.refresh();

	return container;	
	}

	function normalItem(item:CollectionItem,container:MovieClip):MovieClip{
		var textObject:TextField=TextField(collection.getItem(item.getKey()).getValue());
		textObject.setTextFormat(getNormalFormat().getFormat());
		centerTextObject(textObject);
		textObject._parent.rectangulo.setColor(getNormalFormat().getBackgroundColor());
		textObject._parent.rectangulo.setAlpha(getNormalFormat().getBackgroundAlpha());
		textObject._parent.rectangulo.refresh();
		
	return container;	
	}

	function hoverItem(item:CollectionItem,container:MovieClip):MovieClip {
		//Busco en mi coleccion el array y lo
		var textObject:TextField=TextField(collection.getItem(item.getKey()).getValue());
		textObject.setTextFormat(getHoverFormat().getFormat());
		centerTextObject(textObject);
		textObject._parent.rectangulo.setColor(getHoverFormat().getBackgroundColor());
		textObject._parent.rectangulo.setAlpha(getHoverFormat().getBackgroundAlpha());
		textObject._parent.rectangulo.refresh();
		
	return container;	
	}

	function border(container:MovieClip):MovieClip {
		//Dibuja la base
		mask.removeMovieClip();
		mcBorde.removeMovieClip();
		var rect:Rectangulo= new Rectangulo(container,BORDER_SIZE,BORDER_SIZE,container.width-BORDER_SIZE*2,container.height-BORDER_SIZE*2,COLOR_BG,ALPHA_BG);
		back=rect.getClip();
		//Dibujas los bordes o los detalles de afuera.
		var borde:Rectangulo= new Rectangulo(container._parent,container._x+BORDER_SIZE,container._y+BORDER_SIZE,
		container.width-BORDER_SIZE*2,container.height-BORDER_SIZE*2,BORDER_COLOR,BORDER_ALPHA,false);
		borde.setBordes(BORDER_SIZE, BORDER_COLOR, BORDER_ALPHA, false, true);
		mcBorde=borde.getClip();
		//Dibuja la mascara
		var rMask:Rectangulo=new Rectangulo(container._parent,container._x+BORDER_SIZE, container._y+BORDER_SIZE, back._width, back._height, 0, ALPHA_DEBUG_MASK);
		mask=rMask.getClip();
		container.setMask(mask);
		
		return container;
	}
	
	function reset():Void{
		collection=new Collection();
	}
	
}